<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" name="flowuser" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">申请人部门</label>
                        <div class="layui-input-block">
                            <input type="text" name="flowdept" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">用途</label>
                        <div class="layui-input-block">
                            <input type="text" name="yong" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">使用日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="usedt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">预计归还日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="yudt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">领取方式：</label>
                        <div class="layui-input-block">
                            <select id="lingtype" name="lingtype" lay-filter="lingtype">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">借证状态：</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select id="status" name="status" lay-filter="status">
                                <option value="">请选择</option>
                                <option value="1">流程（审批通过）</option>
                                <option value="0">流程（审批中）</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="enginid" name="enginid">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var currButAuth, currTabData, mytable, table, form, treeObj, deptTreeData=[];
    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('借证申请');
        mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_cert_borrow_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                var lingtype_str = '<option value="">请选择</option>';
                var lingtype = res.data.lingtype;
                for (var key in lingtype){
                    if(res.data.is_lingtype == key){
                        lingtype_str += '<option value="'+key+'" selected>'+lingtype[key]+'</option>';
                    }else {
                        lingtype_str += '<option value="'+key+'">'+lingtype[key]+'</option>';
                    }

                }
                $("#lingtype").html(lingtype_str);


                var state_str = '<option value="">请选择</option>';
                var state = res.data.state;
                for (var key in state){
                    if(res.data.is_state == key){
                        state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                    }else {
                        state_str += '<option value="'+key+'">'+state[key]+'</option>';
                    }

                }
                $("#state").html(state_str);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,list_bill_cols_str
                ,{field: 'state_name', title: '借证状态'}
                ,{field: 'flowuser', title: '申请人'}
                ,{field: 'created_at', title: '申请时间'}
                ,{field: 'yong', title: '用途'}
                ,{field: 'nums', title: '借证数量'}
                ,{field: 'usedt', title: '使用日期'}
                ,{field: 'yudt', title: '预计归还日期'}
                ,{field: 'lingtype_name', title: '领取方式'}
                ,{field: 'qudt', title: '取证时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }

                            if(currButAuth[key].butname == 'qu'){
                                if(currTabData[index].state != 0){
                                    continue;
                                }
                            }

                            if(currButAuth[key].butname == 'gui'){
                                if(currTabData[index].state == 0){
                                    continue;
                                }
                            }

                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add_flow(){
        openPageEdit('flow_add.php?close=1');
    }
    function auth_but_func_qu(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('qu.php?close=1&id='+trData.id, '770px', '490px');
    }
    function auth_but_func_gui(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('gui.php?close=1&id='+trData.id);
    }
    function auth_but_func_mingxi(){
        openPageEdit('mingxi.php');
    }






</script>
</body>
</html>
